package agency.tango.materialintro;

import agency.tango.materialintroscreen.parallax.ParallaxComponentContainer;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;
import org.jetbrains.annotations.NotNull;
import agency.tango.materialintro.ResourceTable;

public class DemoView extends ParallaxComponentContainer {

    private int index;
    private Text mTv;

    public DemoView(Context context, int index) {
        super(context);
        this.index = index;
        setPageNum();
    }

    private void setPageNum() {
        if (mTv != null) {
            mTv.setText("this is page-" + index);
        }
    }

    public DemoView(Context context, AttrSet attrSet, int index) {
        super(context, attrSet);
        this.index = index;
        setPageNum();
    }

    public DemoView(Context context, AttrSet attrSet, String styleName, int index) {
        super(context, attrSet, styleName);
        this.index = index;
        setPageNum();
    }

    @Override
    protected void initView() {
        if (mContext == null || mContext.get() == null) {
            return;
        }
        mRootView = LayoutScatter.getInstance(mContext.get()).parse(ResourceTable.Layout_layout_test_view, null, false);
        if (mRootView == null) {
            return;
        }
        mTv = (Text) mRootView.findComponentById(ResourceTable.Id_txt_title);
    }

    @Override
    public @NotNull Component getRootView() {
        return mRootView;
    }
}
